<template>
  <el-drawer
    :title="nickName+'-邀请信息'"
    :visible.sync="drawer_open"
    size="950px"
    append-to-body
  >
    <div class="user">
      <!--搜索表单-->
      <div class="common-seach-wrap">
        <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="关键词">
            <el-input v-model="formInline.nick_name" placeholder="请输入昵称|用户ID"></el-input>
          </el-form-item>
          <!-- <el-form-item label="会员等级">
            <el-select v-model="formInline.grade_id" placeholder="请选择">
              <el-option label="全部" value="0"></el-option>
              <el-option v-for="(item, index) in gradeList" :key="index" :label="item.name" :value="item.grade_id">
              </el-option>
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item label="来源">
            <el-select v-model="formInline.reg_source" placeholder="请选择">
              <el-option label="全部" value=""></el-option>
              <el-option label="小程序" value="wx"></el-option>
              <el-option label="APP" value="app"></el-option>
              <el-option label="H5" value="h5"></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="注册时间">
            <div class="block">
              <span class="demonstration"></span>
              <el-date-picker v-model="formInline.reg_date" type="daterange" value-format="yyyy-MM-dd"
                              range-separator="至"
                              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
          </el-form-item>

          <el-form-item>
          <el-button size="small" type="success" @click="onExport">导出</el-button>
        </el-form-item>
        </el-form>


      </div>
      <!--内容-->
      <div class="product-content">
        <div class="table-wrap">
          <el-table size="small" :data="tableData" border style="width: 100%" height="calc(100vh - 280px)" v-loading="loading">
            <el-table-column prop="user_id" label="用户ID" width="80"></el-table-column>
            <el-table-column prop="nickName" label="昵称"></el-table-column>
            <el-table-column prop="nickName" label="微信头像">
              <template slot-scope="scope">
                <img :src="scope.row.avatarUrl" width="30px" height="30px"/>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="" label="会员等级">
              <template slot-scope="scope">
                <span v-if="scope.row.grade_id == 0">无等级</span>
                <span v-else>{{ scope.row.grade.name }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="mobile" label="来源">
              <template slot-scope="scope">
                <span v-if="scope.row.reg_source == 'wx'">小程序</span>
                <span v-if="scope.row.reg_source == 'app'">APP</span>
                <span v-if="scope.row.reg_source == 'h5'">H5</span>
              </template>
            </el-table-column> -->
            <!-- <el-table-column prop="points" label="积分"></el-table-column>
            <el-table-column prop="balance" label="余额"></el-table-column> -->
            <!-- <el-table-column prop="mobile" label="手机号"></el-table-column> -->
            <el-table-column prop="create_time" label="注册时间" width="140"></el-table-column>
          </el-table>
        </div>

        <!--分页-->
        <div class="pagination">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
                         :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
                         :total="totalDataNumber"></el-pagination>
        </div>
      </div>
    </div>
  </el-drawer>
</template>
<script>
import UserApi from '@/api/user.js';
import qs from 'qs';
export default {
  components: {},
  data() {
    return {
      activeName: 'all',
      drawer_open: false,
      /*是否加载完成*/
      loading: false,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      formInline: {
        nick_name: '',
        grade_id: '',
        reg_date: '',
        tag_id: 0,
        reg_source: '',
      },
      isLogistics: false,
      logisticsData: {},
      exStyle: [],
      showDetail: false,
      order_id: 0,
      gradeList: [],
    }
  },
  props: ['open_referee', 'referee_id', 'nickName'],
  watch: {
    drawer_open(value) {
      this.$emit('update:open_referee', value);
    },
    open_referee(value) {
      this.drawer_open = value;
    },
    referee_id() {
      this.curPage = 0;
      this.getData();
    }
  },
  methods: {

    onExport: function () {
      let baseUrl =
        process.env.NODE_ENV === "development"
          ? window.location.protocol + "//" + window.location.host
          : process.env.VUE_APP_API_URL;
      window.location.href = baseUrl + '/index.php/supplier/supplier.supplier/export?' + qs.stringify(this.formInline);
    },

    /*跨多列*/
    arraySpanMethod(row) {
      if (row.rowIndex % 2 == 0) {
        if (row.columnIndex === 0) {
          return [1, 8];
        }
      }
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.getData();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getData();
    },
    getData() {
      let self = this;
      let Params = self.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      Params.referee_id = this.referee_id;
      self.loading =true;
      UserApi.userlist(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
          self.gradeList = data.data.grade;
        })
        .catch(error => {
          self.loading = false;
        });
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.tableData = [];
      this.getData();
    },
    addClick(row) {
      this.order_id = row.order_id;
      this.showDetail = true;
    },
    /*切换菜单*/
    handleClick(tab, event) {
      let self = this;
      self.curPage = 1;
      self.getData();
    },
  }
}
</script>
<style scoped>
.user {
  padding: 20px;
  padding-top: 0;
}
</style>
